<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <meta content="telephone=no" name="format-detection">

    <link rel="stylesheet" href="/gupiao/css/weui.css">
    <link rel="stylesheet" href="/gupiao/css/jquery-weui.css">
    <link rel="stylesheet" href="/gupiao/css/style.css">
    <link rel="stylesheet" href="http://at.alicdn.com/t/font_689900_ih252kqm5i.css">

    <style>
        .weui-grid__icon .iconfont{font-size: 28px;color:#999;}
        .index-top-fix .fright{font-size: 25px;position: absolute;right: 20px;color: #4b5361;top: 0;}
    </style>
</head>
<body class="back1">

<div class="index-top-fix">
    <a href="{:url('gupiao.index/index')}" class="iconfont icon-left- left"></a>
    {if $type == 'remark'}
        <p class="title">个股点评（{$count}支股票）</p>
    {else/}
        <p class="title">个股推荐（{$count}支股票）</p>
    {/if}
    <a href="javascript:;" class="fright iconfont icon-paixu" id="paixu"></a>
</div>

<div class="mt50"></div>

<div class="weui-search-bar" id="searchBar">

    <form class="weui-search-bar__form" id="search" action="" method="post">
        <div class="weui-search-bar__box">
            <i class="weui-icon-search"></i>
            <input type="hidden" name="type" id="type" value="{$type}">
            <input type="search" class="weui-search-bar__input" name="keyword" id="searchInput" placeholder="搜索" required="">
            <a href="javascript:" class="weui-icon-clear" id="searchClear"></a>
        </div>
        <label class="weui-search-bar__label" id="searchText">
            <i class="weui-icon-search"></i>
            <span>搜索</span>
        </label>
    </form>
    <a href="javascript:" class="weui-search-bar__cancel-btn" id="searchCancel">取消</a>
    <a href="javascript:" onclick="login()" class="weui-search-bar__cancel-btn" > 确定</a>

</div>

<div class="gegu-list-box">
    <ul>
        <li>
            <p>股票名称</p>
            <p>股票代码</p>
            <p>更新时间</p>
            <p>关注人数</p>
        </li>
    </ul>
    <ul id="list"></ul>
</div>

<div class="weui-loadmore" id="loadmore">
    <i class="weui-loading"></i>
    <span class="weui-loadmore__tips">正在加载</span>
</div>

<div class="weui-loadmore" id="loadall" style="display:none;">
    <span class="weui-loadmore__tips">已加载所有</span>
</div>

<!--客服调用-->
<div class="kefu" style="display:none;">
    <a href="tel:{$web_config.kf_tel}">
        <div class="iconbox">
            <i class="iconfont icon-kefu1"></i>
        </div>
    </a>
</div>

<div id="half" class="weui-popup__container popup-bottom">
    <!--<div class="weui-popup__overlay close-popup"></div>-->
    <div class="weui-popup__modal" style="height:136px;">
        <div class="toolbar">
            <div class="toolbar-inner">
                <a href="javascript:;" class="picker-button close-popup">关闭</a>
                <h1 class="title">
                    管理
                </h1>
            </div>
        </div>
        <div class="modal-content" >
            <div class="weui-flex">

                <a href="javascript:;" class="weui-grid js_grid" id="addLive">
                    <div class="weui-grid__icon">
                    <i class="iconfont icon-jia"></i>
                </div>
                    <p class="weui-grid__label">
                        新建点评
                    </p>
                </a>

                <a href="javascript:;" class="weui-grid js_grid" id="continue">
                    <div class="weui-grid__icon">
                        <i class="iconfont icon-jixu1"></i>
                    </div>
                    <p class="weui-grid__label">
                        继续点评
                    </p>
                </a>

                <a href="javascript:;" class="weui-grid js_grid" id="editlist">
                    <div class="weui-grid__icon">
                        <i class="iconfont icon-bianji"></i>
                    </div>
                    <p class="weui-grid__label">
                        编辑
                    </p>
                </a>

                <a href="javascript:;" class="weui-grid js_grid" id="deletelist">
                    <div class="weui-grid__icon">
                        <i class="iconfont icon-shanchu"></i>
                    </div>
                    <p class="weui-grid__label">
                        删除
                    </p>
                </a>

            </div>
        </div>
    </div>
</div>

<div>
    <!--这个是用户的uid-->
    <input type="hidden" name="uid" id="uid" value="{:session('uid')}">
    <!--这个是用户的身份级别-->
    <input type="hidden" name="admin1" id="admin1" value="{$admin1}">
</div>

<script src="/gupiao/js/jquery.min.js"></script>
<script src="/gupiao/js/jquery-weui.min.js"></script>

<script>

/*$("#paixu").on('click', function (){
    $.alert({
        title: '排序方式',
        text: 
            '<div class="weui-cells weui-cells_radio" id="radiopx">'+
                '<label class="weui-cell weui-check__label" for="x11">'+
                    '<div class="weui-cell__bd" style="width:70px;">'+
                        '<p>关注人数</p>'+
                    '</div>'+
                    '<div class="weui-cell__ft" style="width:70px;">'+
                        '<input type="radio" class="weui-check" name="radio1" vname="enlist" id="x11" checked="checked">'+
                        '<span class="weui-icon-checked"></span>'+
                    '</div>'+
                '</label>'+
                '<label class="weui-cell weui-check__label" for="x12">'+
                    '<div class="weui-cell__bd" style="width:70px;">'+
                        '<p>更新时间</p>'+
                    '</div>'+
                    '<div class="weui-cell__ft" style="width:70px;">'+
                        '<input type="radio" class="weui-check" id="x12" name="radio1" vname="last_live_time">'+
                        '<span class="weui-icon-checked"></span>'+
                    '</div>'+
                '</label>'+
            '</div>',
        onOK: function () {
            //点击确认
            gupiao_list(0);
        }
    });

})*/

$("#paixu").on('click',function(){
    gupiao_list(0,1);
    setTimeout(function () {
        location.reload();
    },1500);

    // 返回顶部
    // window.scrollTo(0,0);
});

// 第一页数据
gupiao_list(0);

// 检索
function login()
{
    gupiao_list(0);

    // 返回顶部
    window.scrollTo(0,0);
}

//解决多次点击
var onid = 0;
var alertid = 0;

function gupiao_list(_page,sort=0)
{
    // 页面递增
    _page++;

    var loading = false;  //状态标记

    var type    = document.getElementById("type").value;
    var admin1  = document.getElementById("admin1").value;

    // 检索条件
    var keyword = document.getElementById('searchInput').value;

    // 排序
    // var sort = $('#radiopx').find('input[type="radio"]:checked').attr('vname');


    $.ajax({
        type : "GET",
        url : "{:url('xcx/lists')}",
        data:{type:type,page:_page,keyword:keyword,sort:sort},
        dataType:'json',
        success : function (res) {

            if(res.code == 200){
                var banner  = res.data;
                var html    = '';

                for(var i=0;i<banner.length;i++){

                    var data = res.data[i];

                    if(data.is_new == "1"){
                        html += "<li money='"+data.price+"' lid='"+data.live_id+"'><p class='al'><i class='iconfont icon-xin'></i>"+data.name+"</p><p>"+data.code+"</p><p>"+data.last_live_time +"</p><p>"+data.enlist+"人</p>" +
                            "<input type='hidden' name='id' id='"+data.id+"'></li>";
                    } else if(data.is_new == "0"){
                        html += "<li money='"+data.price+"' lid='"+data.live_id+"' ><p class='al'>"+data.name+"</p><p>"+data.code+"</p><p>"+data.last_live_time +"</p><p>"+data.enlist+"人</p>" +
                            "<input type='hidden' name='id' id='"+data.id+"'></li>";
                    }
                }

                // 数据展示方式
                if(_page == 1){
                    $("#list").html(html);    
                }else{
                    $("#list").append(html);
                }

                // locading  这个时候关闭
                if(res.data.length < 15){

                    $(document.body).destroyInfinite();
                    $("#loadmore").hide();
                    $("#loadall").show();

                }else{

                    // 滚动加载
                    $(document.body).infinite().on("infinite", function() {
                        if(loading){
                            return;
                        }

                        loading = true;

                        // 模拟延迟
                        setTimeout(function() {

                            gupiao_list(_page);
                            loading = true;

                        }, 1000);
                    })

                }

                
                // 点击操作
                var pid;
                var lveid;
                // 讲师身份点击
                if(admin1 == 1){
                    // if(onid == 0){
                        // 优化多次点击
                        // onid ++;
                        $('#list li').off('click').on('click', function(){

                            // 获取到的是股票名称的 id
                            pid = $(this).find("input").attr('id'); //获取的id

                            var halfTitle = $(this).find(".al").text();

                            $("#half").find("h1.title").text(halfTitle+' '+'管理');
                            $("#half").popup();

                        });
                    // }
                    

                }else if(admin1 == 0){

                    $('#list li').on('click', function(){

                        // 要获取到股票标题id
                        lveid = $(this).attr('lid');
                        money = $(this).attr('money');

                        // 是否创建点评
                        if(lveid<=0){
                            alert('抱歉，讲师未点评该股票');
                            return;
                        }

                        $.ajax({
                            type: "POST",                       // 方法类型
                            dataType: "json",                   // 预期服务器返回的数据类型
                            url: "{:url('xcx/order')}",        // url
                            data: {id:lveid},
                            success: function (res) {

                                // 已购买
                                if(res.code == 1){

                                    location.href ="{:url('index/live_in')}?id="+lveid;

                                }else if(res.code == 0){

                                    // 这里要拿到用户购买需要支付的金额
                                    if(money > 0){
                                        var strMoney = "确认支付"+money+"元吗？支付后未更新点评前不用再付费！";
                                    }else{
                                        var strMoney = "本只股票点评免费，欢迎长期关注";
                                    }
                                    

                                    $.confirm(strMoney, "点评付款提示", function() {
                                        // 点击确认后的回调函数   调用支付
                                        $.ajax({
                                            type: "POST",                       // 方法类型
                                            dataType: "json",                   // 预期服务器返回的数据类型
                                            url: "{:url('xcx/buy')}",        // url
                                            data: {id:lveid},
                                            success: function (res) {

                                                // 成功
                                                if (res.code == 200) {
                                                    
                                                    location.href ="{:url('index/live_in')}?id="+lveid;

                                                // 余额不足
                                                }else if(res.code = 402){

                                                    // 跳转前去充值界面
                                                    // alert('余额不足,请充值')
                                                    alert(res.dest)
                                                    location.href ="{:url('gupiao.mycenter/recharge')}";
                                                    return;
                                                  
                                                // 错误 
                                                }else{
                                                    alert(res.msg);
                                                    return;
                                                }
                                            }
                                        })
                                    }, function() {
                                        //点击取消后的回调函数
                                    });

                                }else{
                                    alert("未知错误");
                                }

                            }
                        })

                    });

                }


                // if(alertid == 0){

                //     alertid ++;
                    // 这个是新建点评的触发事件
                    $("#addLive").off('click').on('click',function(){
                        location.href ="{:url('gupiao.lists/addlive')}?id="+pid;
                    });

                    // 这个是读股票进行编辑
                    $("#editlist").off('click').on('click',function(){
                        location.href ="{:url('gupiao.lists/editlist')}?id="+pid;
                    });

                    // 这个是进入之前点评 进行继续点评
                    $("#continue").off('click').on('click',function() {

                        $.ajax({
                            type: "POST",                               // 方法类型
                            dataType: "json",                           // 预期服务器返回的数据类型
                            url: "{:url('gupiao.gupiao/continu')}",     // url
                            data: {id:pid},
                            success: function (res) {
                                if (res.code == 200) {

                                    location.href ="{:url('index/live/in')}?id="+res.live_id.id;
                                } else if (res.code == 400){

                                    alert('没有正在直播的！')

                                } else if (res.code == 401){
                                    alert('请求网络异常！')
                                }
                            }
                        })

                    });

                    // 删除股票
                    $("#deletelist").off('click').on('click',function(){
                        $.ajax({
                            type: "POST",                       //方法类型
                            dataType: "json",                   //预期服务器返回的数据类型
                            url: "{:url('gupiao.gupiao/show')}",        //url
                            data: {id:pid},
                            success: function (res) {
                                if (res.code == 200) {
                                    alert(res.dest)
                                    location.href ="{:url('gupiao.index/index')}";
                                } else if (res.code == 400){
                                    alert(res.dest)
                                }
                            }
                        })
                    });
                // }
                


            } else {
                alert('请求失败');
            }
        }
    });
    
    // 重置点击优化
    // onid    = 0;
    // alertid = 0;

}
</script>

<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>
    //
    wx.config({
        debug: false,
        appId: '{$jsconfig.appId}',
        timestamp: '{$jsconfig.timestamp}',
        nonceStr: '{$jsconfig.noncestr}',
        signature: '{$jsconfig.signature}',
        jsApiList: [
            'checkJsApi',
            'onMenuShareTimeline',
            'onMenuShareAppMessage',
            'onMenuShareQQ',
            'onMenuShareWeibo',
            'hideMenuItems',
            'showMenuItems',
            'hideAllNonBaseMenuItem',
            'showAllNonBaseMenuItem',
            'translateVoice',
            'startRecord',
            'stopRecord',
            'onRecordEnd',
            'playVoice',
            'pauseVoice',
            'stopVoice',
            'uploadVoice',
            'downloadVoice',
            'chooseImage',
            'previewImage',
            'uploadImage',
            'downloadImage',
            'getNetworkType',
            'openLocation',
            'getLocation',
            'hideOptionMenu',
            'showOptionMenu',
            'closeWindow',
            'scanQRCode',
            'chooseWXPay',
            'openProductSpecificView',
            'addCard',
            'chooseCard',
            'openCard'
        ]
    });
    wx.isInit = false;

    wx.ready(function () {

        //分享给朋友
        wx.onMenuShareAppMessage({
            title: "每日更新股票点评",            // 分享标题 此处$title可在控制器端传递也可在页面传递 页面传递讲解在下面哦
            desc: "一哥股票点评，提供专业，靠谱的股票点评",             // 分享描述
            link: "{$web_url}",  // 分享链接
            imgUrl: "{$share_icon}",   // 分享图标
            type: '', // 分享类型,music、video或link，不填默认为link
            dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
            success: function () {
                alert('分享成功');
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                alert('取消分享');
            }
        });
        //分享到朋友圈
        wx.onMenuShareTimeline({
            title: "每日更新股票点评",               // 分享标题
            desc: "一哥股票点评，提供专业，靠谱的股票点评",                // 分享描述
            link: "{$web_url}",      // 分享链接
            imgUrl: "{$share_icon}",         // 分享图标
            success: function () {
                // 用户确认分享后执行的回调函数
                alert('分享成功');
            },
            cancel: function () {
                // 用户取消分享后执行的回调函数
                alert('取消分享');
            }
        });
    });

    wx.error(function (res) {
        alert(res.errMsg);
    });


</script>

</body>
</html>

